/*  -------------------------- (C) COPYRIGHT 2020 Fortiortech ShenZhen ---------------------------*/
/*  File Name      : AddFunction.c
/*  Author         : Fortiortech  Appliction Team
/*  Version        : V1.0
/*  Date           : 2020-08-21
/*  Description    : This file contains  function used for Motor Control.
/*  ----------------------------------------------------------------------------------------------*/
/*                                     All Rights Reserved
/*  ----------------------------------------------------------------------------------------------*/

#include "MyProject.h"

/* Private variables ---------------------------------------------------------*/
/*电机保护相关*/
FaultStateType mcFaultSource;       //错误状态标志位
FaultVarible xdata mcFaultDect;     //错误计数
//ProtectVarible xdata mcProtectTime; //保护标志位

/*电机控制变量*/
bool idata FR;
FOCCTRL xdata mcFocCtrl;
MCRAMP idata MotorSpeed;
//BL_150 xdata BLDC150;
/*ONOFF测试*/
ONVarible ONOFFTest;


/*  -------------------------------------------------------------------------------------------------
    Function Name  : StarRampDealwith
    Description    :
    Date           : 2020-04-10
    Parameter      : None
    ------------------------------------------------------------------------------------------------- */
void StarRampDealwith(void)
{

    uint8 ANGLE_MTemp, ANGLE_DTemp;

    if ((BLDC.BLDCSetFlag == 2) && (mcState == mcRun))
    {
        /*  -------------------------------------------------------------------------------------------------
                屏蔽续流时间（角度）设置
                -------------------------------------------------------------------------------------------------*/
        ANGLE_MTemp = (uint8)(TIM1_CR1 & 0x7F); //读取当前的续流屏蔽和延迟换相
        ANGLE_DTemp = (uint8)(TIM1_CR2 & 0x7F);

        if (ANGLE_MASK_R(Motor_Mask_Angle) > ANGLE_MTemp) //如果目标的续流屏蔽角度 > 当前续流屏蔽角度
        {
            TIM1_CR1 = (TIM1_CR1 & (0x80)) | (ANGLE_MTemp + 1); //当前续流屏蔽角度+1
        }
        else if (ANGLE_MASK_R(Motor_Mask_Angle) < ANGLE_MTemp) //如果目标的续流屏蔽角度 < 当前续流屏蔽角度
        {
            TIM1_CR1 = (TIM1_CR1 & (0x80)) | (ANGLE_MTemp - 1); //当前续流屏蔽角度-1
        }

        /*  -------------------------------------------------------------------------------------------------
            检测到过零点后的延迟换相时间（角度）设置
            -------------------------------------------------------------------------------------------------*/

        {
            if ((ANGLE_DELAY_R((30 - Motor_Advance_Angle)) + 0x01) > ANGLE_DTemp) //如果目标的延迟换相蔽角度 > 当前延迟换相角度
            {
                TIM1_CR2 = (TIM1_CR2 & (0x80)) | (ANGLE_DTemp + 1); //当前延迟换相角度+1
            }
            else if ((ANGLE_DELAY_R((30 - Motor_Advance_Angle)) + 0x01) < ANGLE_DTemp) //如果目标的延迟换相蔽角度 < 当前延迟换相角度
            {
                TIM1_CR2 = (TIM1_CR2 & (0x80)) | (ANGLE_DTemp - 1); //当前延迟换相角度-1
            }
        }

    }
}










